home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / mail / deldupes10.lha / DelDupes.br
Text File  |  1995-08-28  |  3KB  |  107 lines

  1. /*
  2. ** $VER: DelDupes.br 1.0 (28.8.95)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** This script will delete duplicate entries in the file database.  The first
  6. ** occurence of each filename will be kept, subsequent occurences in any file
  7. ** area will be deleted (currently, I'll do something about this later).
  8. **
  9. ** After running I'd recommend you use "Maintainance" in Thor's file database
  10. ** window.
  11. **
  12. **
  13. ** Usage: DelDupes.br <SYSTEM>
  14. **
  15. ** Ideas: GUI interface if run from Thor
  16. **        Use bbsread's READARGS
  17. **        Allow identical filenames across file areas
  18. **        An ALL command line switch to scan all systems
  19. **        Optionally pack file data
  20. **
  21. */
  22.  
  23. options results
  24.  
  25. signal on break_c
  26. signal on halt
  27.  
  28. /* Find BBSREAD ARexx ports' */
  29.  
  30. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  31.  
  32. /* Parse command line arguments */
  33.  
  34. parse arg system
  35. system = strip(system, 'B', '"')
  36.  
  37. if system = '' then do
  38.     say 'Usage: DelDupes.br <SYSTEM>'
  39.     exit(0)
  40.     end
  41.  
  42. /* Initialize variables */
  43.  
  44. checked = 0; totchecked = 0; dupes = 0; dupeshere = 0
  45.  
  46. FDF_DELETED = '00000001'x
  47.  
  48. /* Start the work... */
  49.  
  50. address(BBSREAD)
  51. GETFAREALIST BBSNAME '"'system'"' STEM fareas
  52. if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  53.  
  54. if fareas.COUNT = 0 then do
  55.     say 'No file areas on this system.'
  56.     exit(0)
  57.     end
  58.  
  59. say '1B'x'[4mChecking for dupes on "'system'" - 'fareas.COUNT' file areas.' || '1B'x'[0m' || '1B'x'[1B'
  60.  
  61. do i = 1 to fareas.COUNT
  62.     drop fadata.
  63.     GETFAREADATA BBSNAME '"'system'"' FAREANAME '"'fareas.i'"' STEM fadata
  64.     if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  65.  
  66.     say '1B'x'[1A' || '1B'x'[K' || '1B'x'[1m'fareas.i || '1B'x'[0m'
  67.     say '1B'x'[1A' || '1B'x'[20Ccontains 'fadata.NUMFILES' files.'
  68.     say '1B'x'[1A' || '1B'x'[42C' || '1B'x'[3mProcessing...' || '1B'x'[0m' || '1B'x'[1B'
  69.  
  70.     thisfile = fadata.FIRSTFILE
  71.  
  72.     if fadata.NUMFILES > 0 then do until checked = fadata.NUMFILES
  73.         drop filetags. filedata. found.
  74.         READBRFILE BBSNAME '"'system'"' FAREANAME '"'fareas.i'"' FILENR thisfile TAGSSTEM filetags DATASTEM filedata
  75.         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  76.         nextfile = result
  77.  
  78.         if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then do
  79.             SEARCHBRFILE BBSNAME '"'system'"' STEM found SEARCH '"'filetags.NAME'"' NAME
  80.             if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  81.  
  82.             do j = 1 to found.FILEAREA.COUNT
  83.                 do k = 1 to found.FILE.j.COUNT
  84.                     if found.FILE.j.k ~= thisfile then do
  85.                         say '1B'x'[1A' || '1B'x'[KDupe: 'found.FILEAREA.j'/'filetags.NAME
  86.                         WRITEBRFILE BBSNAME '"'system'"' FAREANAME '"'found.FILEAREA.j'"' UPDATEFILENR found.FILE.j.k DELETEFILE
  87.                         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  88.  
  89.                         say '1B'x'[1A' || '1B'x'[42CDELETED'
  90.                         dupes = dupes + 1; dupeshere = dupeshere + 1
  91.                         end
  92.                     end
  93.                 end
  94.  
  95.             checked = checked + 1; totchecked = totchecked + 1
  96.             thisfile = nextfile
  97.             end
  98.         end
  99.  
  100.     say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[K'dupeshere' dupes found.' || '1B'x'[1B'
  101.     checked = 0; dupeshere = 0
  102.     end
  103.  
  104. break_c:
  105. halt:
  106. say 'Checked 'totchecked' files and found 'dupes' duplicates.'
  107.